<?php

/*	Created by Alexander Alexandrov aka SS

			hazg@mail.ru				*/
define('SSLIB_Ui', TRUE);
if(!defined("SSLIB_Page")) die("Page class missing");

$g_stylesPrinted = array();

class Ui
{
	
	static function Frame($text, $img, $style1 = "", $left = 13, $top = 13, $right = 13, $bottom = 13)
	{
		//MSIE 6.0
		$ext = "png";
		//$addstyle = "";
		if(preg_match('/MSIE (\d)\.0/', $_SERVER['HTTP_USER_AGENT'], $matches) > 0)
		{
			if($matches[1]<7)
			{
		//		$ext = "gif";
			/*	if(preg_match("/alpha-(\d\d)/", $img, $matches))
				{
					$add = "filter:alpha(opacity=".$matches[1].");";
				}*/
			}
		}
		
		//if(!Page::ValidateObject()) die('Ui::Frame can be used only in Page content');
		global $g_stylesPrinted;
		$style = "";
		$class_img = "fi_$img";
		
		$class_size = "fs_".dechex($left).dechex($top).dechex($right).dechex($bottom);
		if(empty($g_stylesPrinted["$class_img"]))
		{
			$g_stylesPrinted["$class_img"] = true;
			Page::Style("
			.ui_fi_$img .content, 
			.ui_fi_$img .t, 
			.ui_fi_$img .b, 
			.ui_fi_$img .b 
			div
			{
				background:transparent url(/images/ui/frames/$img.$ext) no-repeat top right;
			}
			", Page::INSERT_BEGIN);
		}		
		if(empty($g_stylesPrinted["$class_size"]))
		{
				$g_stylesPrinted[$class_size] = true;
				Page::Style(".ui_$class_size  {}
.ui_$class_size .b div {width:12px;margin-left:-12px;}
.ui_$class_size .t {width:12px;margin-left:-12px;}
.ui_$class_size .content {padding:0px 12px 0px 0px;}
.ui_$class_size .b, 
.ui_$class_size .b div {height:10px;}");
		}
		if(empty($g_stylesPrinted["frame_main_css"]))
		{
			$g_stylesPrinted["frame_main_css"] = true;
			///*max-width:760px;*/
			Page::Style("
.ui_frame {".$style1." position:relative;margin:0px auto;min-width:8em;margin-left:0px;z-index:1;margin-bottom:0.5em;}
.ui_frame .content {position:relative;zoom:1;_overflow-y:hidden;}
.ui_frame .t {position:absolute;left:0px;top:0px;height:100%;_height:1600px;background-position:top left;}
.ui_frame .b {position:relative;width:100%;}
.ui_frame .b, .ui_frame .b div {font-size:1px;}
.ui_frame .b {background-position:bottom right;}
.ui_frame .b div {position:relative;background-position:bottom left;}
.ui_frame .wrapper {position:static;max-height:1000px;overflow:auto;}");
		}
		
		return
		"<div class=\"ui_frame ui_$class_img ui_$class_size\"><div class=\"content\"><div class=\"wrapper\"><div class=\"t\"></div></div><div class=\"frameBody\">
		$text
		</div></div><div class=\"b\"><div></div></div></div>
		";
	}
}